package com.bdqn.oa.dao.impl;

import com.bdqn.oa.dao.PlanCommentDao;
import com.bdqn.oa.entity.PlanComment;
import com.bdqn.oa.utils.DateUtils;
import com.bdqn.oa.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author Zhouxw
 * @date 2022/7/21 20:23
 */
public class PlanCommentDaoImpl implements PlanCommentDao {
    QueryRunner queryRunner = new QueryRunner();

    /**
     * 新增一条计划点评数据
     *
     * @param planComment 计划点评
     * @return 影响行数
     */
    @Override
    public int savePlanComment(PlanComment planComment) throws SQLException {
        String sql = "insert into plan_comment (datetime, content, `name`) value (?, ?, ?)";
        int result = queryRunner.update(DruidUtils.getConnection(), sql, planComment.getDatetime(), planComment.getContent(), planComment.getName());
        return result;
    }

    /**
     * 通过id获取计划点评数据
     *
     * @param id id
     * @return 计划点评
     */
    @Override
    public PlanComment getPlanCommentById(Integer id) throws SQLException {
        String sql = "select * from plan_comment where id = ?";
        PlanComment planComment = queryRunner.query(DruidUtils.getConnection(),sql,new BeanHandler<>(PlanComment.class),id);
        return  planComment;
    }
}
